package com.yc.taixin.controller;

import com.yc.taixin.support.utils.WechatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用户模块
 * 注释:view层不应该有太复杂的逻辑
 */
@RestController
@RequestMapping("/wx")
@CrossOrigin
public class WxPublicController extends BaseController {
	private static final Logger log = LoggerFactory.getLogger(WxPublicController.class);

	@GetMapping("/serial")
	public String checkSign(HttpServletRequest request, HttpServletResponse response) {
		try {
			String signature = request.getParameter("signature");
			String timestamp = request.getParameter("timestamp");
			String nonce = request.getParameter("nonce");
			String echostr = request.getParameter("echostr");
			log.info("本身" + signature);
			if (WechatUtils.checkSignature(signature, timestamp, nonce)) {
				return echostr;
			}
		} catch (Exception e) {
			log.error("验证公众号token失败", e);
		}
		return null;
	}

}
